    <p class="titulo"><?php echo $msg->get('Autoria_Problemas') ?></p>
    <p class="titulo"><?php echo $msg->get('Sistemas') ?> - <?php echo $msg->get('Menu_Metodos_Diretos') ?></p>
<?php
	switch(@$_GET['modo'])
	{
		case 'criar':
			exibe_criar();
			break;
		case 'alterar':
			exibe_alterar();
			break;
		case 'remover':
			exibe_remover();
			break;
		default:
			exibe_opcoes();
	}


	function exibe_opcoes()
	{
        global $msg;
?>
		<form name="opcoes" action="index.php" method="GET">
			<p><input type="radio" name="modo" value="criar" id="criar"><label for="criar"><?php echo $msg->get('XML_GERA_MSG02') ?></label></p>
			<p><input type="radio" name="modo" value="alterar" id="alterar"><label for="alterar"><?php echo $msg->get('XML_GERA_MSG12') ?></label></p>
			<p><input type="radio" name="modo" value="remover" id="remover"><label for="remover"><?php echo $msg->get('XML_GERA_MSG13') ?></label></p>
            <p><input type="hidden" name="inc" value="seal_direto.php">
			<p><input type="submit" class="button" name="proximo" value=<?php echo $msg->get('XML_NEXT') ?>></p>
		</form>

<?php
	}

	function exibe_criar()
	{
        global $msg;
		if (empty($_POST['dim']) || intval($_POST['dim']) == 0 || intval($_POST['dim']) > 6)
		{
			if (intval(@$_POST['dim']) > 6)
			{
?>
		<p><font color="red">O n&uacute;mero m&aacute;ximo da dimens&atilde;o &eacute; 6.</font></p>
<?php
			}
?>
		<form name="criar" action="index.php?inc=seal_direto.php&modo=criar" method="POST">
			<p><label for="dimensao"><?php echo $msg->get('XML_GERA_SELA_MSG01') ?></label> <input type="text" name="dim" size="2" id="dimensao"></p>
			<p><input class="button" type="button" name="voltar" value=<?php echo $msg->get('XML_BACK') ?> onClick="history.back(1)"> <input type="submit" class="button" name="proximo" value=<?php echo $msg->get('XML_NEXT') ?>></p>
		</form>
<?php
		}
		elseif (!isset($_POST['cria']))
		{
			$dim = intval($_POST['dim']);
?>
		<form name="criar" action="index.php?inc=seal_direto.php&modo=criar" method="POST">
			<p><label for="dimensao"><?php echo $msg->get('XML_GERA_SELA_MSG01') ?></label> <?php echo $dim; ?><input type="hidden" name="dim" value="<?php echo $dim ?>"></p>
			<p><?php echo $msg->get('XML_GERA_SELA_MSG018') ?></p>
			<p>
				<table>
<?php
			for ($i = 0; $i < $dim; $i++)
			{
				echo "\t\t\t\t\t<tr>\n";
				for ($j = 0; $j <= $dim; $j++)
				{
					if ($j != 0)
						echo "\t\t\t\t\t\t<td>".(($j == $dim)?'=':'+')."</td>\n";
					if ($j != $dim)
						echo "\t\t\t\t\t\t<td><input type=\"text\" name=\"a[$i][$j]\" size=\"2\">X<sub>".($j+1)."</sub></td>\n";
					else
						echo "\t\t\t\t\t\t<td><input type=\"text\" name=\"a[$i][$j]\" size=\"2\"></td>\n";
				}
				echo "\t\t\t\t\t</tr>\n";
			}
?>
				</table>
			</p>
			<p>
				<table>
					<tr>
						<td><?php echo $msg->get('XML_GERA_SELA_MSG05') ?>:</td>
						<td><input type="radio" name="tiposolucao" value="compatible_determined" id="cd"><label for="cd"><?php echo $msg->get('XML_GERA_SELA_MSG06') ?></label></td>
					</tr>
					<tr>
						<td>&nbsp;</td>
						<td><input type="radio" name="tiposolucao" value="compatible_undetermined" id="ci"><label for="ci"><?php echo $msg->get('XML_GERA_SELA_MSG07') ?></label></td>
					</tr>
					<tr>
						<td>&nbsp;</td>
						<td><input type="radio" name="tiposolucao" value="unsolvable" id="id"><label for="id"><?php echo $msg->get('XML_GERA_SELA_MSG08') ?></label></td>
					</tr>
				</table>
			</p>
			<p>
				<table>
					<tr>
						<td></td>
						<td><p><?php echo $msg->get('XML_GERA_SELA_MSG09') ?></p></td>
						<td><p><?php echo $msg->get('XML_GERA_SELA_MSG010') ?></p></td>
					</tr>
					<tr>
						<td><p><?php echo $msg->get('XML_GERA_SELA_MSG011') ?></p></td>
						<td><input type="radio" name="symetric" value="symetric"></td>
						<td><input type="radio" name="symetric" value="nonsymetric"></td>
					</tr>
					<tr>
						<td><p><?php echo $msg->get('XML_GERA_SELA_MSG012') ?></p></td>
						<td><input type="radio" name="sparse" value="sparse"></td>
						<td><input type="radio" name="sparse" value="nonsparse"></td>
					</tr>
					<tr>
						<td><p><?php echo $msg->get('XML_GERA_SELA_MSG013') ?></p></td>
						<td><input type="radio" name="defpos" value="positive_definite"></td>
						<td><input type="radio" name="defpos" value="nonpositive_definite"></td>
					</tr>
					<tr>
						<td><p><?php echo $msg->get('XML_GERA_SELA_MSG014') ?></p></td>
						<td><input type="radio" name="diagdom" value="diagonally_dominant"></td>
						<td><input type="radio" name="diagdom" value="nondiagonally_dominant"></td>
					</tr>
				</table>
			</p>
			<p><label for="dsc"><?php echo $msg->get('Descricao') ?>:</label></p>
			<p><textarea name="desc" id="dsc" cols="30" rows="3"></textarea></p>
			<p><label for="com"><?php echo $msg->get('XML_GERA_MSG08') ?></label></p>
			<p><textarea name="com" id="com" cols="30" rows="3"></textarea></p>
			<p><label for="ref"><?php echo $msg->get('XML_GERA_MSG09') ?></label></p>
			<p><textarea name="ref" id="ref" cols="30" rows="3"></textarea></p>
			<p><input type="button" class="button" value=<?php echo $msg->get('XML_BACK') ?> onClick="history.back(1)"><input type="submit" class="button" name="cria" value="<?php echo $msg->get('Finalizar') ?>"></p>
		</form>
<?php
		}
		else
		{
			function numerico($matriz)
			{
				if (is_array($matriz))
				{
					foreach ($matriz as $m)
						if (!numerico($m)) return false;
					return true;
				}
				else
					return (is_numeric($matriz) || empty($matriz));
			}
			if (!numerico($_POST['a']))
			{
?>
		<p><font color="red">Os dados do sistema devem ser num&eacute;ricos</font></p>
		<p><input type="button" class="button" value="< Voltar" onClick="history.back(1)"></p>
<?php
			}
			elseif (empty($_POST['desc']))
			{
?>
		<p><font color="red">A descri&ccedil;&atilde;o &eacute; obrigat&oacute;ria</font></p>
		<p><input type="button" class="button" value="< Voltar" onClick="history.back(1)"></p>
<?php
			}
			else
			{
				function xmlentities($xml)
				{
					$entities = array ('<' => '&lt;','&' => '&amp;',);
					if (is_string($xml)) { $xml = strtr($xml, $entities);}
					return $xml;
				}
				global $DOCUMENT_ROOT;
				//$dir_user = $DOCUMENT_ROOT."/user/".$_SESSION['id_usuario'];
                //$arq_xml = $DOCUMENT_ROOT."/user/".$_SESSION['id_usuario']."/biblioteca.xml";
                $arq_xml = $_SESSION['ANAWEB']->RetornaArquivoBiblioteca();
				/*if (!is_dir($dir_user))
				{
					mkdir ($dir_user);
				}*/
				if (!is_file($arq_xml))
				{
					$doc = new DOMDocument();
				}
				else
				{
					$doc = new DOMDocument();
            		$doc->preserveWhiteSpace=false;
					$doc = DOMDocument::load($arq_xml);
				}
				$doc->formatOutput=true;
				if ($doc->getelementsbytagname("problems")->length == 0)
				{
					$raiz = $doc->createElement("problems");
					$raiz = $doc->appendChild($raiz);
				}
				$raiz = $doc->getelementsbytagname("problems")->item(0);
		
				if ($doc->getelementsbytagname("lin_systems")->length == 0) {
					$filho = $doc->createElement("lin_systems");
					$filho = $raiz->appendChild($filho);
				}
				$filho = $doc->getelementsbytagname("lin_systems")->item(0);
				$system = $doc->createElement("system");
				$system = $filho->appendChild($system);
				$method = $doc->createElement("method",utf8_encode('direct'));
				$method = $system->appendChild($method);
				$descri = $doc->createElement("description",xmlentities(utf8_encode($_POST['desc'])));
				$descri = $system->appendChild($descri);
				$ord = $doc->createElement("dim",$_POST['dim']);
				$ord = $system->appendChild($ord);
				for($i = 0; $i < $_POST['dim']; $i++)
				{ 	$lin = $doc->createElement("row");
					$lin = $system->appendChild($lin);
					for($j = 0; $j <= $_POST['dim']; $j++)
					{ 	$x = $doc->createElement("x",$_POST['a'][$i][$j]);
						$x = $lin->appendChild($x);
					}
				}
				if (!empty($_POST['com'])) {
					$comen = $doc->createElement("comments",xmlentities(utf8_encode($_POST['com']))); 
					$comen = $system->appendChild($comen);
				}
				if (!empty($_POST['ref'])) {
					$refer = $doc->createElement("reference",xmlentities(utf8_encode($_POST['ref'])));
					$refer = $system->appendChild($refer);
				}
				if (!empty($_POST['tiposolucao']))
				{
					$prop = $doc->createElement("properties");
					$prop->setAttribute("type_solution",$_POST['tiposolucao']);
					$prop = $system->appendChild($prop);
				}
				if (!empty($_POST['symetric']))
				{
					$prop = $doc->createElement("properties");
					$prop->setAttribute("symetric",$_POST['symetric']);
					$prop = $system->appendChild($prop);
				}
				if (!empty($_POST['sparse']))
				{
					$prop = $doc->createElement("properties");
					$prop->setAttribute("sparsity",$_POST['sparse']);
					$prop = $system->appendChild($prop);
				}
				if (!empty($_POST['defpos']))
				{
					$prop = $doc->createElement("properties");
					$prop->setAttribute("positive_definite",$_POST['defpos']);
					$prop = $system->appendChild($prop);
				}
				if (!empty($_POST['diagdom']))
				{
					$prop = $doc->createElement("properties");
					$prop->setAttribute("diagonally_dominant",$_POST['diagdom']);
					$prop = $system->appendChild($prop);
				}
				$doc->save($arq_xml);
?>
		<p>Problema criado com sucesso!</p>
		<p><a href="index.php?inc=seal_direto.php">In&iacute;cio</a></p>
<?php
			} // else (formulario de envio para novo problema valido)
		} // else (formulario de envio)
	} //funcao para criar novos problemas

	function exibe_alterar()
	{
		global $DOCUMENT_ROOT,$msg;
		//$dir_user = $DOCUMENT_ROOT."/user/".$_SESSION['id_usuario'];
		//$arq_xml = $DOCUMENT_ROOT."/user/".$_SESSION['id_usuario']."/biblioteca.xml";
        $arq_xml=$_SESSION['ANAWEB']->RetornaArquivoBiblioteca();

		if (!isset($_POST['proximo']) && !isset($_POST['altera']))
		{
			if (is_file($arq_xml))
			{
				$objeto = new DOMDocument();
				$objeto->load($arq_xml);
				$filho = $objeto->getelementsbytagname("lin_systems");
				if ($filho->length > 0)
				{
?>
	<form name="alterar" action="index.php?inc=seal_direto.php&modo=alterar" method="POST">
		<p><?php echo $msg->get('Selecione_Exemplo_Alterado') ?></p>
<?php
					$temp = $filho->item(0)->getelementsbytagname("system");
					$j = 1;
					for($i = 0; $i < $temp->length; $i++)
					{
						$method = $temp->item($i)->getelementsbytagname("method");
						$conteudo = $method->item(0)->nodeValue;
						$dim = $temp->item($i)->getelementsbytagname("dim");
						$dim = $dim->item(0)->nodeValue;
						if ($conteudo == 'direct')
						{
?>
		<p><input type="radio" name="exemplo" value="<?php echo $i ?>" id="ex<?php echo $j ?>"><label for="ex<?php echo $j ?>"><?php echo $msg->get('Exemplo') ?> <?php echo $j ?> (<?php echo $msg->get('dimensao') ?> <?php echo $dim ?>)</label></p>
<?php
							$j++;
						}
					}
?>
		<p><input type="button" class="button" name="voltar" value=<?php echo $msg->get('XML_BACK') ?> onClick="history.back(1)"><input type="submit" class="button" name="proximo" value=<?php echo $msg->get('XML_NEXT') ?>></p>
	</form>
<?php
				}
				else
				{
					echo "\t<p>N&atilde;o constam exemplos desse tipo de problema na sua biblioteca de exemplos</p>\n";
				}
			} else { echo "\t<p>Voc&ecirc; n&atilde;o tem uma biblioteca de exemplos</p>\n"; }
		}
		elseif (!isset($_POST['altera']))
		{
			global $DOCUMENT_ROOT;
			//$dir_user = $DOCUMENT_ROOT."/user/".$_SESSION['id_usuario'];
			//$arq_xml = $DOCUMENT_ROOT."/user/".$_SESSION['id_usuario']."/biblioteca.xml";
            $arq_xml = $_SESSION['ANAWEB']->RetornaArquivoBiblioteca();
			if (is_file($arq_xml))
			{
				$objeto = new DOMDocument();
				$objeto->load($arq_xml);
				$filho = $objeto->getelementsbytagname("lin_systems");
				if ($filho->length > 0)
				{
					$temp = $filho->item(0)->getelementsbytagname("system");

					$dim = $temp->item($_POST['exemplo'])->getelementsbytagname("dim");
					$dim = ($dim->length)?$dim->item(0)->nodeValue:"";

					$dsc = $temp->item($_POST['exemplo'])->getelementsbytagname("description");
					$dsc = ($dsc->length)?$dsc->item(0)->nodeValue:"";

					$ref = $temp->item($_POST['exemplo'])->getelementsbytagname("reference");
					$ref = ($ref->length)?$ref->item(0)->nodeValue:"";

					$com = $temp->item($_POST['exemplo'])->getelementsbytagname("comments");
					$com = ($com->length)?$com->item(0)->nodeValue:"";

					$properties = $temp->item($_POST['exemplo'])->getelementsbytagname("properties");
					$props = array("tiposolucao" => 'nd', "simetrico" => 'nd', "esparso" => 'nd', "defpos" => 'nd', "diagdom" => 'nd');
					foreach ($properties as $prop )
					{
						if ($prop->hasAttribute("type_solution"))
						{
							$props['tiposolucao'] = $prop->getAttribute("type_solution");
						}
						elseif ($prop->hasAttribute("symetric"))
						{
							$props['simetrico'] = $prop->getAttribute("symetric");
						}
						elseif ($prop->hasAttribute("sparsity"))
						{
							$props['esparso'] = $prop->getAttribute("sparsity");
						}
						elseif ($prop->hasAttribute("positive_definite"))
						{
							$props['defpos'] = $prop->getAttribute("positive_definite");
						}
						elseif ($prop->hasAttribute("diagonally_dominant"))
						{
							$props['diagdom'] = $prop->getAttribute("diagonally_dominant");
						}
					}
?>
		<form name="alterar" action="index.php?inc=seal_direto.php&modo=alterar" method="POST">
			<input type="hidden" name="exemplo" value="<?php echo $_POST['exemplo'] ?>">
			<p><label for="dimensao"><?php echo $msg->get('XML_GERA_SELA_MSG01') ?></label> <?php echo $dim; ?><input type="hidden" name="dim" value="<?php echo $dim ?>"></p>
			<p><?php echo $msg->get('XML_GERA_SELA_MSG018') ?>:</p>
			<p>
				<table>
<?php
					$matriz = $temp->item($_POST['exemplo'])->getelementsbytagname("row");
					for($i = 0; $i < $matriz->length; $i++)
					{
						$x = $matriz->item($i)->getelementsbytagname("x");
						for($j = 0; $j < $x->length; $j++)
						{
							$mt[$i][$j] = $x->item($j)->nodeValue;
						}
					}

					for ($i = 0; $i < $dim; $i++)
					{
						echo "\t\t\t\t\t<tr>\n";
						for ($j = 0; $j <= $dim; $j++)
						{
							if ($j != 0)
								echo "\t\t\t\t\t\t<td>".(($j == $dim)?'=':'+')."</td>\n";
							if ($j != $dim)
								echo "\t\t\t\t\t\t<td><input type=\"text\" name=\"a[$i][$j]\" size=\"2\"".(($mt[$i][$j])?" value=\"".$mt[$i][$j]."\"":"").">X<sub>".($j+1)."</sub></td>\n";
							else
								echo "\t\t\t\t\t\t<td><input type=\"text\" name=\"a[$i][$j]\" size=\"2\"".(($mt[$i][$j])?" value=\"".$mt[$i][$j]."\"":"")."></td>\n";
						}
						echo "\t\t\t\t\t</tr>\n";
					}
?>
				</table>
			</p>
			<p>
				<table>
					<tr>
						<td><?php echo $msg->get('XML_GERA_SELA_MSG05') ?>:</td>
						<td><input type="radio" name="tiposolucao" value="compatible_determined" id="cd"<?php if ($props['tiposolucao'] == "compatible_determined") echo " checked"; ?>><label for="cd"><?php echo $msg->get('XML_GERA_SELA_MSG06') ?></label></td>
					</tr>
					<tr>
						<td>&nbsp;</td>
						<td><input type="radio" name="tiposolucao" value="compatible_undetermined" id="ci"<?php if ($props['tiposolucao'] == "compatible_undetermined") echo " checked"; ?>><label for="ci"><?php echo $msg->get('XML_GERA_SELA_MSG07') ?></label></td>
					</tr>
					<tr>
						<td>&nbsp;</td>
						<td><input type="radio" name="tiposolucao" value="unsolvable" id="id"<?php if ($props['tiposolucao'] == "unsolvable") echo " checked"; ?>><label for="id"><?php echo $msg->get('XML_GERA_SELA_MSG08') ?></label></td>
					</tr>
				</table>
			</p>
			<p>
				<table>
					<tr>
						<td></td>
						<td><p><?php echo $msg->get('XML_GERA_SELA_MSG09') ?></p></td>
						<td><p><?php echo $msg->get('XML_GERA_SELA_MSG010') ?></p></td>
					</tr>
					<tr>
						<td><p><?php echo $msg->get('XML_GERA_SELA_MSG011') ?></p></td>
						<td><input type="radio" name="symetric" value="symetric"<?php if ($props['simetrico'] == "symetric") echo " checked"; ?>></td>
						<td><input type="radio" name="symetric" value="nonsymetric"<?php if ($props['simetrico'] == "nonsymetric") echo " checked"; ?>></td>
					</tr>
					<tr>
						<td><p><?php echo $msg->get('XML_GERA_SELA_MSG012') ?></p></td>
						<td><input type="radio" name="sparse" value="sparse"<?php if ($props['esparso'] == "sparse") echo " checked"; ?>></td>
						<td><input type="radio" name="sparse" value="nonsparse"<?php if ($props['esparso'] == "nonsparse") echo " checked"; ?>></td>
					</tr>
					<tr>
						<td><p><?php echo $msg->get('XML_GERA_SELA_MSG013') ?></p></td>
						<td><input type="radio" name="defpos" value="positive_definite"<?php if ($props['defpos'] == "positive_definite") echo " checked"; ?>></td>
						<td><input type="radio" name="defpos" value="nonpositive_definite"<?php if ($props['defpos'] == "nonpositive_definite") echo " checked"; ?>></td>
					</tr>
					<tr>
						<td><p><?php echo $msg->get('XML_GERA_SELA_MSG014') ?></p></td>
						<td><input type="radio" name="diagdom" value="diagonally_dominant"<?php if ($props['diagdom'] == "diagonally_dominant") echo " checked"; ?>></td>
						<td><input type="radio" name="diagdom" value="nondiagonally_dominant"<?php if ($props['diagdom'] == "nondiagonally_dominant") echo " checked"; ?>></td>
					</tr>
				</table>
			</p>
			<p><label for="dsc"><?php echo $msg->get('Descricao') ?>:</label></p>
			<p><textarea name="desc" id="dsc" cols="30" rows="3"><?php if (!empty($dsc)) echo $dsc; ?></textarea></p>
			<p><label for="com"><?php echo $msg->get('XML_GERA_MSG08') ?></label></p>
			<p><textarea name="com" id="com" cols="30" rows="3"><?php if (!empty($com)) echo $com; ?></textarea></p>
			<p><label for="ref"><?php echo $msg->get('XML_GERA_MSG09') ?></label></p>
			<p><textarea name="ref" id="ref" cols="30" rows="3"><?php if (!empty($ref)) echo $ref; ?></textarea></p>
			<p><input type="button" class="button" value=<?php echo $msg->get('XML_BACK') ?> onClick="history.back(1)"><input type="submit" class="button" name="altera" value="<?php echo $msg->get('Alterar') ?>"></p>
		</form>
<?php
				}
			}
			else { echo "\t<p>Voc&ecirc; n&atilde;o tem uma biblioteca de exemplos</p>\n"; }
		}
		else
		{
			function xmlentities($xml)
			{
				$entities = array ('<' => '&lt;','&' => '&amp;',);
				if (is_string($xml)) { $xml = strtr($xml, $entities);}
				return $xml;
			}


			global $DOCUMENT_ROOT;
			//$dir_user = $DOCUMENT_ROOT."/user/".$_SESSION['id_usuario'];
			//$arq_xml = $DOCUMENT_ROOT."/user/".$_SESSION['id_usuario']."/biblioteca.xml";
            $arq_xml = $_SESSION['ANAWEB']->RetornaArquivoBiblioteca();
			if (is_file($arq_xml))
			{
				$objeto = new DOMDocument();
            	$objeto->preserveWhiteSpace=false;
				$objeto->load($arq_xml);
				$objeto->formatOutput=true;
				$filho = $objeto->getelementsbytagname("lin_systems");
				if ($filho->length > 0)
				{
					$temp = $filho->item(0)->getelementsbytagname("system");

					$dim = $temp->item($_POST['exemplo'])->getelementsbytagname("dim");
					$dim->item(0)->nodeValue = $_POST['dim'];

					$dsc = $temp->item($_POST['exemplo'])->getelementsbytagname("description");
					$dsc->item(0)->nodeValue = xmlentities(utf8_encode($_POST['desc']));

					$ref = $temp->item($_POST['exemplo'])->getelementsbytagname("reference");
					if (!empty($_POST['ref']))
					{
						if ($ref->length)
							$ref->item(0)->nodeValue = xmlentities(utf8_encode($_POST['ref']));
						else
						{
							$ref = $objeto->createElement("reference",xmlentities(utf8_encode($_POST['ref'])));
							$ref = $temp->item($_POST['exemplo'])->appendChild($ref);
						}
							
					}
					else
					{
						if ($ref->length)
							$ref->item(0)->nodeValue = "";
					}

					$com = $temp->item($_POST['exemplo'])->getelementsbytagname("comments");
					if (!empty($_POST['com']))
					{
						if ($com->length)
							$com->item(0)->nodeValue = xmlentities(utf8_encode($_POST['com']));
						else
						{
							$com = $objeto->createElement("comments",xmlentities(utf8_encode($_POST['ref'])));
							$com = $temp->item($_POST['exemplo'])->appendChild($com);
						}
							
					}
					else
					{
						if ($com->length)
							$com->item(0)->nodeValue = "";
					}
					
					
					$properties = $temp->item($_POST['exemplo'])->getelementsbytagname("properties");
					$foram = array ( false, false, false, false, false );
					foreach ($properties as $prop)
					{
						if ($prop->hasAttribute("type_solution") && !empty($_POST['tiposolucao']))
						{
							$prop->setAttribute("type_solution",$_POST['tiposolucao']);
							$foram[0] = true;
						}
						elseif ($prop->hasAttribute("symetric") && !empty($_POST['symetric']))
						{
							$prop->setAttribute("symetric",$_POST['symetric']);
							$foram[1] = true;
						}
						elseif ($prop->hasAttribute("sparsity") && !empty($_POST['sparse']))
						{
							$prop->setAttribute("sparsity",$_POST['sparse']);
							$foram[2] = true;
						}
						elseif ($prop->hasAttribute("positive_definite") && !empty($_POST['defpos']))
						{
							$prop->setAttribute("positive_definite",$_POST['defpos']);
							$foram[3] = true;
						}
						elseif ($prop->hasAttribute("diagonally_dominant") && !empty($_POST['diagdom']))
						{
							$prop->setAttribute("diagonally_dominant",$_POST['diagdom']);
							$foram[4] = true;
						}
					}
					if (!empty($_POST['tiposolucao']) && $foram[0] == false)
					{
						$prop = $objeto->createElement("properties");
						$prop->setAttribute("type_solution",$_POST['tiposolucao']);
						$prop = $temp->item($_POST['exemplo'])->appendChild($prop);
					}
					if (!empty($_POST['symetric']) && $foram[1] == false)
					{
						$prop = $objeto->createElement("properties");
						$prop->setAttribute("symetric",$_POST['symetric']);
						$prop = $temp->item($_POST['exemplo'])->appendChild($prop);
					}
					if (!empty($_POST['sparse']) && $foram[2] == false)
					{
						$prop = $objeto->createElement("properties");
						$prop->setAttribute("sparsity",$_POST['sparse']);
						$prop = $temp->item($_POST['exemplo'])->appendChild($prop);
					}
					if (!empty($_POST['defpos']) && $foram[3] == false)
					{
						$prop = $objeto->createElement("properties");
						$prop->setAttribute("positive_definite",$_POST['defpos']);
						$prop = $temp->item($_POST['exemplo'])->appendChild($prop);
					}
					if (!empty($_POST['diagdom']) && $foram[4] == false)
					{
						$prop = $objeto->createElement("properties");
						$prop->setAttribute("diagonally_dominant",$_POST['diagdom']);
						$prop = $temp->item($_POST['exemplo'])->appendChild($prop);
					}

					$matriz = $temp->item($_POST['exemplo'])->getelementsbytagname("row");
					for($i = 0; $i < $matriz->length; $i++)
					{
						$x = $matriz->item($i)->getelementsbytagname("x");
						for($j = 0; $j < $x->length; $j++)
						{
							$x->item($j)->nodeValue=$_POST['a'][$i][$j];
						}
					}

					$objeto->save($arq_xml);
?>
		<p>Problema alterado com sucesso!</p>
		<p><a href="index.php?inc=seal_direto.php">In&iacute;cio</a></p>
<?php
				}
			}
		}
	}

	function exibe_remover()
	{
        global $msg;
		if (!isset($_POST['proximo']) && !isset($_POST['remove']))
		{
			global $DOCUMENT_ROOT;
			//$dir_user = $DOCUMENT_ROOT."/user/".$_SESSION['id_usuario'];
			//$arq_xml = $DOCUMENT_ROOT."/user/".$_SESSION['id_usuario']."/biblioteca.xml";
            $arq_xml = $_SESSION['ANAWEB']->RetornaArquivoBiblioteca();
			if (is_file($arq_xml))
			{
				$objeto = new DOMDocument();
				$objeto->load($arq_xml);
				$filho = $objeto->getelementsbytagname("lin_systems");
				if ($filho->length > 0)
				{
?>
	<form name="alterar" action="index.php?inc=seal_direto.php&modo=remover" method="POST">
		<p><?php echo $msg->get('Selecione_Exemplo_Removido') ?>:</p>
<?php
					$temp = $filho->item(0)->getelementsbytagname("system");
					$j = 1;
					for($i = 0; $i < $temp->length; $i++)
					{
						$method = $temp->item($i)->getelementsbytagname("method");
						$conteudo = $method->item(0)->nodeValue;
						$dim = $temp->item($i)->getelementsbytagname("dim");
						$dim = $dim->item(0)->nodeValue;
						if ($conteudo == 'direct')
						{
?>
		<p><input type="radio" name="exemplo" value="<?php echo $i ?>" id="ex<?php echo $j ?>"><label for="ex<?php echo $j ?>"><?php echo $msg->get('Exemplo') ?> <?php echo $j ?> (<?php echo $msg->get('dimensao') ?> <?php echo $dim ?>)</label></p>
<?php
							$j++;
						}
					}
?>
		<p><input type="button" class="button" name="voltar" value=<?php echo $msg->get('XML_BACK') ?> onClick="history.back(1)"><input type="submit" class="button" name="proximo" value=<?php echo $msg->get('XML_NEXT') ?>></p>
	</form>
<?php
				}
				else
				{
					echo "\t<p>N&atilde;o constam exemplos desse tipo de problema na sua biblioteca de exemplos</p>\n";
				}
			} else { echo "\t<p>Voc&ecirc; n&atilde;o tem uma biblioteca de exemplos</p>\n"; }
		}
		elseif (!isset($_POST['remove']))
		{
			global $DOCUMENT_ROOT;
			//$dir_user = $DOCUMENT_ROOT."/user/".$_SESSION['id_usuario'];
			$arq_xml = $_SESSION['ANAWEB']->RetornaArquivoBiblioteca();
			if (is_file($arq_xml))
			{
				$objeto = new DOMDocument();
				$objeto->load($arq_xml);
				$filho = $objeto->getelementsbytagname("lin_systems");
				if ($filho->length > 0)
				{
					$temp = $filho->item(0)->getelementsbytagname("system");

					$dim = $temp->item($_POST['exemplo'])->getelementsbytagname("dim");
					$dim = ($dim->length)?$dim->item(0)->nodeValue:"";

					$dsc = $temp->item($_POST['exemplo'])->getelementsbytagname("description");
					$dsc = ($dsc->length)?$dsc->item(0)->nodeValue:"";

					$ref = $temp->item($_POST['exemplo'])->getelementsbytagname("reference");
					$ref = ($ref->length)?$ref->item(0)->nodeValue:"";

					$com = $temp->item($_POST['exemplo'])->getelementsbytagname("comments");
					$com = ($com->length)?$com->item(0)->nodeValue:"";
?>
		<p><?php echo $msg->get('Seguinte_Exemplo_Sera_Removido') ?>:</p>
		<form name="alterar" action="index.php?inc=seal_direto.php&modo=remover" method="POST">
			<input type="hidden" name="exemplo" value="<?php echo $_POST['exemplo'] ?>">
			<p><label for="dimensao"><?php echo $msg->get('XML_GERA_SELA_MSG01') ?></label> <?php echo $dim; ?><input type="hidden" name="dim" value="<?php echo $dim ?>"></p>
			<p><?php echo $msg->get('XML_GERA_SELA_MSG018') ?></p>
			<p>
				<table>
<?php
					$matriz = $temp->item($_POST['exemplo'])->getelementsbytagname("row");
					for($i = 0; $i < $matriz->length; $i++)
					{
						$x = $matriz->item($i)->getelementsbytagname("x");
						for($j = 0; $j < $x->length; $j++)
						{
							$mt[$i][$j] = $x->item($j)->nodeValue;
						}
					}

					for ($i = 0; $i < $dim; $i++)
					{
						echo "\t\t\t\t\t<tr>\n";
						for ($j = 0; $j <= $dim; $j++)
						{
							if ($j != 0)
								echo "\t\t\t\t\t\t<td>".(($j == $dim)?'=':'+')."</td>\n";
							if ($j != $dim)
								echo "\t\t\t\t\t\t<td>".$mt[$i][$j]." * X<sub>$j</sub></td>\n";
							else
								echo "\t\t\t\t\t\t<td>".$mt[$i][$j]."</td>\n";
						}
						echo "\t\t\t\t\t</tr>\n";
					}
?>
				</table>
			</p>
			<p><?php echo $msg->get('Descricao') ?>: <?php if (!empty($dsc)) echo $dsc; ?></p>
			<p><?php echo $msg->get('XML_GERA_MSG08') ?> <?php if (!empty($com)) echo $com; ?></p>
			<p><?php echo $msg->get('XML_GERA_MSG09') ?> <?php if (!empty($ref)) echo $ref; ?></p>
			<p><input type="button" class="button" value=<?php echo $msg->get('XML_BACK') ?> onClick="history.back(1)"><input type="submit" class="button" name="remove" value="<?php echo $msg->get('Remover') ?>"></p>
		</form>
<?php
				}
			}
			else { echo "\t<p>Voc&ecirc; n&atilde;o tem uma biblioteca de exemplos</p>\n"; }
		}
		else
		{
			global $DOCUMENT_ROOT;
			//$dir_user = $DOCUMENT_ROOT."/user/".$_SESSION['id_usuario'];
			$arq_xml = $_SESSION['ANAWEB']->RetornaArquivoBiblioteca();
			if (is_file($arq_xml))
			{
				$objeto = new DOMDocument();
				$objeto->load($arq_xml);
				$pai = $objeto->getelementsbytagname("lin_systems");
				if ($pai->length)
				{
					$filho = $pai->item(0)->getelementsbytagname("system");
					$aremover = $filho->item($_POST['exemplo']);
					$oldfilho = $pai->item(0)->removeChild($aremover);
					$objeto->save($arq_xml);
?>
		<p>Exemplo removido com sucesso</p>
		<p><a href="index.php?inc=seal_direto.php">In&iacute;cio</a></p>
<?php
				}
			}
		}
	}
?>